package commands;

import java.util.HashMap;
import containers.StudentContainer;
import entities.Student;

/**
 * command to add a student to the StudentContainer
 * 
 * @author gke703
 */
public class AddStudent {

	/**
	 * adds student to container
	 * 
	 * @param myStudent
	 *            , Student to be added to system
	 */
	public AddStudent(Student myStudent) {

		HashMap<Integer, Student> students = StudentContainer.dictionary();

		if (!students.containsValue(myStudent)
				&& !students.containsKey(myStudent.getID())) {
			students.put(myStudent.getID(), myStudent);
		}

	}

	/**
	 * checks if student is added to StudentContainer or not
	 * 
	 * @param myStudent
	 *            , Student to be checked
	 * @return boolean, true if in container, false otherwise
	 */
	public boolean isAdded(Student myStudent) {

		HashMap<Integer, Student> students = StudentContainer.dictionary();

		if (students.containsValue(myStudent)) {
			return true;
		} else {
			return false;
		}

	}

	/**
	 * checks if student is added to StudentContainer or not
	 * 
	 * @param myStudent
	 *            , Student to be checked
	 * @return boolean, true if in container, false otherwise
	 */
	public boolean isAdded(int myStudentNum) {

		HashMap<Integer, Student> students = StudentContainer.dictionary();

		if (students.containsKey(myStudentNum)) {
			return true;
		} else {
			return false;
		}

	}

	/**
	 * regression tests
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		AddStudent myAddStudent = new AddStudent(new Student(0, ""));
		myAddStudent = new AddStudent(new Student(2, ""));
		Student myStudent = new Student(3, "");
		myAddStudent = new AddStudent(myStudent);

		if (!myAddStudent.isAdded(0)) {
			System.out.println("problem adding student");
		}

		if (myAddStudent.isAdded(1)) {
			System.out
					.println("problem checking for a student which has not been added");
		}

		if (!myAddStudent.isAdded(myStudent)) {
			System.out.println("Problem adding a student");
		}

	}

}
